package com.app.base.tool;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.app.utils.NetBroadcastReceiver;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import org.xutils.x;

import java.util.HashMap;
import java.util.List;


/**
 * 时间:2015-7-6
 * 公司:DDY
 * 作者:LBH
 * 功能:Fragment 基类
 * @author Administrator
 *
 */
public abstract class BaseFragment extends Fragment implements NetBroadcastReceiver.NetEvevt {

	public static NetBroadcastReceiver.NetEvevt evevt;
	private View rootView;
	public Context ct;
	public DisplayImageOptions options;

	public static HashMap<String,String> fMapKeys = new HashMap<String,String>();

	public BaseFragment(){}
	
	@Override
	public void onActivityCreated(@Nullable Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		initData(savedInstanceState);
	}

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ct = getActivity();

	}

	@Override
	@Nullable
	public View onCreateView(LayoutInflater inflater,
							 @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		rootView = initView(inflater);
		x.view().inject(ct,rootView);
		return rootView;
	}
	

	/**
	 * 获取视图View
	 * @return
	 */
	public View getRootView(){
		return rootView;
	}
	
	/**
	 * 初始化页面
	 * @return
	 */
	public abstract View initView(LayoutInflater inflater);
	
	
	/**
	 * 初始化数据
	 */
	public abstract void initData(Bundle savedInstanceState);
	

	/**
	 * 判断返回值是否存在
	 * @param requestStr
	 * @return
	 */
	public boolean isRequestStr(String requestStr){
		return (requestStr!=null && requestStr.length()>0)?true:false;
	}
	
	/**
	 * 判断(List)返回值是否存在
	 * @param <T>
	 * @param requestList
	 * @return
	 */
	public <T> boolean isRequestList(List<T> requestList){
		return (requestList!=null && requestList.size()>0 )?true:false;
	}
	
	/**
	 * 获取的属性 为空转化为""
	 * @param attribute
	 * @return
	 */
	public String setAttributeText(Object attribute){
		String str = (attribute == null) ?"":attribute.toString();
		return str;
	}
	
	public View stateRefersh(){
	
		rootView = initView(null);
		x.view().inject(ct,rootView);
		initData(null);
		return rootView;
	}
	
	private String getName(){
		return getClass().getSimpleName();
	}
	
	/**
	 * U_MENG
	 */
	public void onResume() {
		super.onResume();
//		MobclickAgent.onPageStart(getName());
	}
	
	public void onPause() {
		super.onPause();
//		MobclickAgent.onPageEnd(getName());
	}


}
